package cn.mw.cmdb.util;

import cn.mw.cmdb.entity.PropertyInfo;
import org.apache.commons.collections.map.ListOrderedMap;
import org.springframework.stereotype.Component;

import java.util.*;

@Component
public class InstanceInfoUtil {
    public void orderInstanceInfoTableFieldList(List<PropertyInfo> list){
        Collections.sort(list, new Comparator<PropertyInfo>() {
            @Override
            public int compare(PropertyInfo o1, PropertyInfo o2) {
                return o1.getName().compareTo(o2.getName());
            }
        });
    }

    public Map orderInstanceInfoMap(Map map){
        Map ret = new ListOrderedMap();
        List<String> list = new ArrayList<>(map.keySet());
        orderInstanceInfoKeyList(list);
        for(String key:list){
            ret.put(key ,map.get(key));
        }
        return ret;
    }

    public void orderInstanceInfoKeyList(List<String> list){
        Collections.sort(list);
    }
}
